home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / dev / lang / fpc09905c.lha / fpc / inc / m68k.inc < prev    next >
Text File  |  1998-09-21  |  25KB  |  865 lines

  1. {
  2.     $Id: m68k.inc,v 1.10 1998/08/17 12:26:04 carl Exp $
  3.     This file is part of the Free Pascal run time library.
  4.     Copyright (c) 1993,97 by Carl-Eric Codere,
  5.     member of the Free Pascal development team.
  6.  
  7.     See the file COPYING.FPC, included in this distribution,
  8.     for details about the copyright.
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13.  
  14.  **********************************************************************}
  15. {****************************************************************************
  16.  
  17.       m68k.inc : Processor dependent implementation of system unit
  18.                  For Motorola 680x0 Processor.
  19.  
  20. *****************************************************************************}
  21.  
  22. {****************************************************************************}
  23. {   Credit where credit is due:                                              }
  24. {   -Some of the copy routines taken from the Atari dlib source code:        }
  25. {     Dale Schumacher (alias: Dalnefre')  dal@syntel.uucp                    }
  26. {     399 Beacon Ave. St. Paul, MN 55104,USA                                 }
  27. {   -Some of the routines taken from the freeware ATARI Sozobon C compiler   }
  28. {      1988 by Sozobon, Limited.  Author: Johann Ruegg (freeware)            }
  29. {  Thanks to all these people wherever they maybe today!                     }
  30. {****************************************************************************}
  31.  
  32.  
  33.     { Don't call the following routines directly. }
  34.  Procedure Hlt;[public,alias: 'HALT_ERROR'];
  35.  { called by code generator on run-time errors. }
  36.  { on entry contains d0 = error code.           }
  37.  var
  38.   b:byte; { only byte is used... }
  39.  begin
  40.   asm
  41.      move.b d0,b
  42.   end;
  43.      HandleError(b);
  44.  end;
  45.  
  46.  
  47.  
  48.  
  49.    Procedure FillChar(var x; count: longint; value: byte);
  50.    begin
  51.      asm
  52.       move.l 8(a6), a0      { destination                   }
  53.       move.l 12(a6), d1     { number of bytes to fill       }
  54.       move.b 16(a6),d0      { fill data                     }
  55.       cmpi.l #65535, d1     { check, if this is a word move }
  56.       ble    @LMEMSET3      { use fast dbra mode            }
  57.       bra @LMEMSET2
  58.     @LMEMSET1:
  59.       move.b d0,(a0)+
  60.     @LMEMSET2:
  61.       subq.l #1,d1
  62.       cmp.b #-1,d1
  63.       bne  @LMEMSET1
  64.       bra @LMEMSET5        { finished slow mode , exit     }
  65.  
  66.     @LMEMSET4:             { fast loop mode section 68010+ }
  67.       move.b d0,(a0)+
  68.     @LMEMSET3:
  69.       dbra d1,@LMEMSET4
  70.  
  71.     @LMEMSET5:
  72.      end ['d0','d1','a0'];
  73.    end;
  74.  
  75.    Procedure FillObject(var x; count: longint; value: byte);
  76.    begin
  77.      asm
  78.       move.l 8(a6), a0      { destination                   }
  79.       move.l 12(a6), d1     { number of bytes to fill       }
  80.       move.w 16(a6),d0      { fill data                     }
  81.       cmp.l  #65535, d1     { check, if this is a word move }
  82.       ble    @LMEMSET3      { use fast dbra mode            }
  83.       bra @LMEMSET2
  84.     @LMEMSET1:
  85.       move.b d0,(a0)+
  86.     @LMEMSET2:
  87.       subq.l #1,d1
  88.       cmp.b #-1,d1
  89.       bne  @LMEMSET1
  90.       bra @LMEMSET5        { finished slow mode , exit     }
  91.  
  92.     @LMEMSET4:             { fast loop mode section 68010+ }
  93.       move.b d0,(a0)+
  94.     @LMEMSET3:
  95.       dbra d1,@LMEMSET4
  96.  
  97.     @LMEMSET5:
  98.      end ['d0','d1','a0'];
  99.    end;
  100.  
  101.     procedure int_help_constructor;
  102.  
  103.       begin
  104.          asm
  105.           XDEF HELP_CONSTRUCTOR
  106.             { Entry without preamble, since we need the ESP of the
  107.               constructor }
  108.             { Stack (relative to %ebp):
  109.                 12 Self
  110.                 8 VMT-Address
  111.                 4 main programm-Addr
  112.                 0 %ebp
  113.             }
  114.             { do we have to initialize self  }
  115.             { we just need to check for zero }
  116.             move.l    a5,d0
  117.             tst.l     d0      { set flags }
  118.             bne       @LHC_4
  119.  
  120.             { get memory, but save register first }
  121.             { temporary variable }
  122.             subq.l #4,sp
  123.             move.l sp,a5
  124.             { Save Registers }
  125.             movem.l d0-a7,-(sp)
  126.             { Memory size }
  127.             move.l 8(a6),a0
  128.             move.l (a0),-(sp)
  129.             { push method pointer }
  130.             move.l a5,-(sp)
  131.             jsr GETMEM
  132.             { Restore all registers in the correct order }
  133.             movem.l (sp)+,d0-a7
  134.             { Memory size to a5 }
  135.             move.l (a5),a5
  136.             add.l  #4,sp
  137.             { If no memory available : fail() }
  138.             move.l a5,d0
  139.             tst.l  d0         { set flags for a5 }
  140.             beq    @LHC_5
  141.             { init self for the constructor }
  142.             move.l a5,12(a6)
  143.          @LHC_4:
  144.             { is there a VMT address ? }
  145.             move.l 8(a6),d0
  146.             or.l   d0,d0
  147.             bne @LHC_7
  148.             { In case the constructor doesn't do anything, the Zero-Flag }
  149.             { can't be put, because this calls Fail() }
  150.             add.l  #1,d0
  151.             rts
  152.          @LHC_7:
  153.             { set zero inside the object }
  154.             { Save Registers }
  155.             movem.l d0-a7,-(sp)
  156.             move.w  #0,-(sp)
  157.  
  158.             move.l  8(a6),a0
  159.             move.l  (a0),-(sp)
  160.             move.l  a5,-(sp)
  161.             {                }
  162.             jsr  FILLOBJECT
  163.             { Restore all registers in the correct order }
  164.             movem.l (sp)+,d0-a7
  165.             { set the VMT address for the new created object }
  166.             move.l 8(a6),d0
  167.             move.l d0,(a5)
  168.             or.l d0,d0
  169.          @LHC_5:
  170.             rts
  171.          end;
  172.       end;
  173.  
  174.     procedure help_fail;
  175.  
  176.       begin
  177.          asm
  178.          end;
  179.       end;
  180.  
  181.     procedure int_help_destructor;
  182.  
  183.       begin
  184.          asm
  185.             { Stack (relative to %ebp):
  186.                 12 Self
  187.                 8 VMT-Address
  188.                 4 Main program-Addr
  189.                 0 %ebp
  190.             }
  191.             { temporary Variable }
  192.           XDEF HELP_DESTRUCTOR
  193.             subq.l #4,sp
  194.             move.l sp,d6
  195.             { Save Registers }
  196.             movem.l d0-a7,-(sp)
  197.  
  198.             move.l 8(a6),d0         { Get the address of the vmt }
  199.             or.l   d0,d0            { Check if there is a vmt    }
  200.             beq    @LHD_3
  201.             { Yes, get size from SELF! }
  202.             move.l 12(a6),a0
  203.             { get VMT-pointer (from Self) to %ebx }
  204.             move.l (a0),a1
  205.             { And put size on the Stack }
  206.             move.l (a1),-(sp)
  207.             { SELF }
  208.             { I think for precaution }
  209.             { that we should clear the VMT here }
  210.             clr.l (a0)
  211.             { get address of local variable into  }
  212.             { address register                    }
  213.             move.l d6,a1
  214.             move.l a0,(a1)
  215.             move.l a1,-(sp)
  216.             jsr    FREEMEM
  217.          @LHD_3:
  218.             { Restore all registers in the correct order }
  219.             movem.l (sp)+,d0-a7
  220.             add.l #4,sp
  221.             rts
  222.          end;
  223.       end;
  224.  
  225.   procedure new_class;assembler;
  226.  
  227.   asm
  228.      XDEF NEW_CLASS
  229.      { create class ? }
  230.      move.l 8(a6), d0
  231.      tst.l  d0
  232.      { check for nil... }
  233.      beq    @NEW_CLASS1
  234.  
  235.      { a5 contains vmt }
  236.      move.l a5,-(sp)
  237.      { call newinstance (class method!) }
  238.      jsr 16(a5)
  239.      { new instance returns a pointer to the new created }
  240.      { instance in d0                                    }
  241.      { load a5  and insert self                          }
  242.      move.l d0,8(a6)
  243.      move.l d0,a5
  244.      bra    @end
  245.   @NEW_CLASS1:
  246.      move.l a5,8(a6)
  247.   @end:
  248.   end;
  249.  
  250.  
  251.  
  252.   procedure dispose_class;assembler;
  253.  
  254.   asm
  255.     XDEF DISPOSE_CLASS
  256.      { destroy class ? }
  257.      move.l 8(a6),d0
  258.      { save self }
  259.      move.l a5,8(a6)
  260.      tst.l  d0
  261.      beq    @DISPOSE_CLASS
  262.      { no inherited call }
  263.      move.l (a5),d0
  264.      { push self }
  265.      move.l a5,-(sp)
  266.      { call freeinstance }
  267.      move.l d0,a0
  268.      jsr    20(a0)
  269.   @DISPOSE_CLASS:
  270.      { load self }
  271.      move.l 8(a6),a5
  272.   end;
  273.  
  274.   { checks for a correct vmt pointer }
  275.   procedure co;assembler;
  276.   { ON ENTRY: a0 -> Pointer to the VMT                  }
  277.   {   Nota: All registers must be preserved including   }
  278.   {   A0 itself!